package com.sinven.serivce;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sinven.common.Pager;
import com.sinven.mapper.CommentMapper;
import com.sinven.pojo.Comment;
import com.sinven.pojo.Content;
import com.sinven.pojo.Leave;

@Service
public class CommentSerivceImpl implements CommentSerivce {

	@Autowired
	private CommentMapper comm;

	@Override
	public long countComment(long tid) {
		return comm.countComment(tid);
	}

	@Override
	public Pager<List<Comment>> queryAll(long startIndex, long pageSize, long tid) {
		// TODO Auto-generated method stub

		// 得到总记录数
		long totalRecords = comm.countComment(tid);
		if (totalRecords == 0) {
			return null;
		}
		Pager<List<Comment>> pager = new Pager<>(totalRecords, startIndex, (int) pageSize);
		List<Comment> contentlist = comm.queryAll(pager.getStartIndex(), pager.getPageSize(), tid);
		pager.setData(contentlist);
		return pager;
	}

	@Override
	public Boolean addComment(Comment comment) {
		return comm.addComment(comment) > 0 ? true : false;
	}

	@Override
	public Boolean deleteComment(Long tid) {
		
		return comm.deleteComment(tid)>0?true:false;
	}

}
